/**
 * 回文 https://zh.wikipedia.org/wiki/%E5%9B%9E%E6%96%87%E6%95%B0
 * * Q1:回文后的溢出问题
 */

isPalindrome = function (x) {
    if (x < 0 || !isFinite(x)) { return false }
    if (x === 0) { return true }
    let max = x
    let sum = 0
    let mode = 0
    while (+max != 0) {
        mode = max % 10
        sum = sum * 10 + mode
        max = max / 10
    }

    if (sum === x) { return true }
    return false
}


/**
 * 
 * 
 * @param {any} x 
 * @returns 
 */
isPalindrome = function (x) {
    if (x < 0 || !isFinite(x)) { return false }
    if (x === 0) { return true }
    let max = x
    let sum = 0
    let mode = 0

    while (+max > 10) {
        mode = max % 10
        sum = sum * 10 + mode
        max = max / 10
    }

    if (sum === ~~x / 10 && max % 10 === x % (10 * sum.length)) { return true }
    return false
}

/**
 * 转为字符串的方法
 */
isPalindrome = function (x) {
    if (x < 0 || !isFinite(x)) { return false }
    if (x === 0) { return true }
    return `${x}` === Array.from(`${Math.abs(x)}`).reverse().join('')
}

isPalindrome = function (x) {
    mid = Math.ceil(x.length / 2)
    left = mid - 1
    right = mid + 1
    arr = Array.from(`${Math.abs(x)}`)
    while (left > 0) {
        if (arr[left] !== arr[right]) return false
        left = left - 1
        right = right + 1
    }
    return true
}








